package com.hwhp.web.console.servlet;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hwhp.entity.Menu;
import com.hwhp.service.console.MenuService;
import com.hwhp.service.console.impl.MenuServiceImpl;
public class FunctionSelectAjax extends HttpServlet {
	
	private MenuService menuService = null ;
	
	public FunctionSelectAjax() {
		super();
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response) {
		String menuid = request.getParameter("functionid");
		String rtn="";
		String rtx="";
		try{
		 List<Menu> subList=new ArrayList();
		 List<Menu> superList=new ArrayList();
		 subList=menuService.getAllSubMenuById(menuid, "1");
		 superList=menuService.getAllFatherMenuById(menuid, "1");
		 String returnXML = "<?xml version=\"1.0\" encoding=\"GBK\"?><root>";
		 for(Menu supMenu:superList){
			 returnXML=returnXML+"<node attr=\"parent\" value=\""+supMenu.getId()+"\"></node>";
		 }
		 for(Menu subMenu:subList){
			 returnXML=returnXML+"<node attr=\"child\" value=\""+subMenu.getId()+"\"></node>";
		 }
		 returnXML=returnXML+"</root>";
		response.setHeader("Content-Type", "text/xml; charset=GBK");
		PrintWriter out = response.getWriter();
		out.print(returnXML);
		out.flush();
		out.close();
		}catch(Exception e){
			e.printStackTrace();
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) {
		this.doGet(request, response);
	}

	public void destroy() {
		super.destroy();
	}

	public void setMenuService(MenuService menuService) {
		this.menuService = menuService;
	}

	public MenuService getMenuService() {
		return menuService;
	}
}
